var Guest=require("../Model/Guest.js");
function GuestControll(app,Mysql)
{
	var GuestModel=Object.create(Guest.GuestModel);
	app.get('/guest/gettodayguest', GetTodayGuests);
	app.get('/guest/getroombooking', GetRoomBooking);
	app.get('/guest/getguestinfobyid', GetGuestInfoById);
	app.get('/guest/getallguestlist',GetAllGuestList);
	app.get('/guest/getallteams', GetAllTeamName);
	app.get('/guest/getnewgstnamebyteam',GetTeamNewGuestName);
	app.post('/guest/checkin', Checkin);
	app.post('/guest/checkout', Checkout);
	app.post('/guest/cancelbooking', CancelBooking);
	app.post('/guest/overstay', OverStay);
	app.post('/guest/newguestinfo', NewGuestInfo);
	app.post('/guest/newcomeinguest', NewComeInGuest);
	

	function GetTodayGuests(req, res, next) {
		var Today=req.query.today;
		var Code=req.query.code;
		GuestModel.GetTodayGuests(Mysql,Code,Today,function(Data){
			res.json(Data);
		});
	}

	function GetAllGuestList(req, res, next){
		var Code=req.query.code;
		GuestModel.GetAllGuestList(Mysql,Code,function(Data){
			res.json(Data);
		});
	}

	function GetAllTeamName(req, res, next){
		var Code=req.query.code;
		GuestModel.GetAllTeamName(Mysql,Code,function(Data){
			res.json(Data);
		});
	}

	function NewGuestInfo(req, res, next){
		var GuestStr=req.body.guestStr;
	  	var GuestInfo=eval("("+GuestStr+")");
        var Code=req.body.code;
		GuestModel.NewGuestInfo(Mysql,Code,GuestInfo,function(Data){
			res.json(Data);
		});
	}

	function NewComeInGuest(req,res,next){
		var GuestStr=req.body.guestStr;
		var Code=req.body.code;
	  	var GuestArr=eval(GuestStr);
	  	GuestModel.NewComeInGuest(Mysql,Code,GuestArr,function(Rst){
			var SR={iRst:Rst};
	  		res.json(SR);
	  	});
	}

	function Checkin(req, res, next) {
		var RoomId=req.body.roomid;
		GuestModel.Checkin(Mysql,RoomId,function(Rst){
			var SR={iRst:Rst};
			res.json(SR);
		});
	}

	function Checkout(req, res, next) {
		var RoomId=req.body.roomid;
		GuestModel.Checkout(Mysql,RoomId,function(Rst){
			var SR={iRst:Rst};
			res.json(SR);
		});
	}

	function CancelBooking(req, res, next) {
	  	var RoomId=req.body.roomid;
	  	var GuestStr=req.body.guestStr;
	  	var GuestArr=eval(GuestStr);

	  	GuestModel.CancelBooking(Mysql,RoomId,GuestArr,function(Rst){
			var SR={iRst:Rst};
	  		res.json(SR);
	  	});
	}

	function OverStay(req, res, next) {
	  	var RoomId=req.body.roomid;
	  	var StayTime=req.body.staytime;
		GuestModel.OverStay(Mysql,RoomId,StayTime,function(Rst){
			var SR={iRst:Rst};
			res.json(SR);
		});
	}

	function GetRoomBooking(req, res, next)
	{
		var Code=req.query.code;
		var RoomId=req.query.roomid;
		var NowTime=req.query.thistime;
		GuestModel.GetRoomBooking(Mysql,Code,RoomId,NowTime,function(Data){
			res.json(Data);
		});
	}

	function GetGuestInfoById(req, res, next)
	{
		var UserId=req.query.uid;
		GuestModel.GetGuestInfoById(Mysql,UserId,function(Data){
			res.json(Data);
		});
	}

	function GetTeamNewGuestName(req, res, next)
	{
		var Code=req.query.code;
		var Team=req.query.team;
		var Index=req.query.index;
		GuestModel.GetTeamNewGuestName(Mysql,Code,Team,Index,function(Data){
			res.json(Data);
		});
	}
}
exports.GuestControll=GuestControll;